﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Baosight.ZNH.ZMCommon.ChildWindows;
using Baosight.ZNH.ZMCommon;
using Baosight.ZNH.ZMCommon.Validators;
using Baosight.Platform.Core.UI.Controls;

namespace Baosight.ZNH.ZMCM.UI
{
    public partial class ZMCMF0 : EFViewCmes
    {
        public ZMCMF0()
        {
            InitializeComponent();
        }

        public override void Initialize(Platform.Core.EIInfo initData)
        {
            this.fdDate.Value = DateTime.Now.ToString("yyyy-MM-dd");
            base.Initialize(initData);
        }

        /// <summary>
        /// 点击下一步按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CommitClick(object sender, RoutedEventArgs e)
        {
            //按钮不可用，防止双击
            Button button = sender as Button;
            button.IsEnabled = false;
            TempButton = button;

            //ValidatorManager自定义的校验方法
            bool result = true;
            ValidatorManager group = this.GetChildObject<ValidatorManager>(null);
            if (group != null)
            {
                result = group.IsValidSucces;
            }

            bool _validateField = ThisValidateField() & this.ValidateField() & result;//确定前的效验

            if (!_validateField)
            {
                this.ValidateMessagePopup();//弹出提示信息
                this.TempButtonOpen(true);//确定按钮生效
            }
            else
            {
                Dictionary<string, string> _args = new Dictionary<string,string>();
                _args.Add("fdDate", this.fdDate.Value.ToString());
                _args.Add("fdDistribute", this.fdDistribute.Value.ToString());
                _args.Add("fdReason", this.fdReason.Value.ToString());
                _args.Add("fdSum", this.fdSum.Value.ToString());
                _args.Add("fdSupplyer", this.fdSupplyer.Value.ToString());
                _args.Add("fdSupplyName", this.fdSupplyName.Value.ToString());
                _args.Add("fdRemark", this.fdRemark.Value.ToString());

                this.Shell.LoadView("ZMCMF1", _args);//将此新增页的录入信息传到新增下一步页面中
            }
        }

        /// <summary>
        /// 点击返回按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void CancelClick(object sender, RoutedEventArgs e)
        {
            foreach (var field in this.spWindows.GetChildObjects<EFDataField>(null, true))
            {
                if (!field.Name.Equals("fdDate"))
                {
                    field.SetDataValue("");
                }
                
            }
        }

        
        /// <summary>
        /// 点击查看所有到货记录按钮
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LookupClick(object sender, RoutedEventArgs e)
        {
            this.Shell.LoadView("ZMCMF2");
        }
    }
}
